package com.ruoyi.factory.staffSafe.controller;

import java.util.*;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.factory.staffSafe.domain.StaffsafeInfo;
import com.ruoyi.factory.staffSafe.service.IStaffsafeInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培训档案人员信息Controller
 * 
 * @author ljj
 * @date 2024-04-15
 */
@RestController
@RequestMapping("/system/staffSafeinfo")
public class StaffsafeInfoController extends BaseController
{
    @Autowired
    private IStaffsafeInfoService staffsafeInfoService;

    /**
     * 查询培训档案人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:staffSafeinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(StaffsafeInfo staffsafeInfo)
    {
        startPage();
        List<StaffsafeInfo> list = staffsafeInfoService.selectStaffsafeInfoList(staffsafeInfo);
        return getDataTable(list);
    }

    /**
     * 导出培训档案人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:staffSafeinfo:export')")
    @Log(title = "培训档案人员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StaffsafeInfo staffsafeInfo)
    {
        List<StaffsafeInfo> list = staffsafeInfoService.selectStaffsafeInfoList(staffsafeInfo);
        ExcelUtil<StaffsafeInfo> util = new ExcelUtil<StaffsafeInfo>(StaffsafeInfo.class);
        util.exportExcel(response, list, "培训档案人员信息数据");
    }

    /**
     * 导出培训档案人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:staffSafeinfo:exportCard')")
    @Log(title = "培训档案人员信息", businessType = BusinessType.EXPORT)
    @RequestMapping("/exportCard")
    public void exportCard(HttpServletResponse response, StaffsafeInfo staffsafeInfo)
    {
        String staffType = staffsafeInfo.getTypeCode();
        String resultType = staffsafeInfo.getResultType();
        startPage();
        List<StaffsafeInfo> list = staffsafeInfoService.exprotStaffsafeInfoList(staffsafeInfo);
        staffsafeInfoService.downloadword(response, list, staffType, resultType);
    }

    /**
     * 获取培训档案人员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:staffSafeinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(staffsafeInfoService.selectStaffsafeInfoById(id));
    }

    /**
     * 新增培训档案人员信息
     */
    @PreAuthorize("@ss.hasPermi('system:staffSafeinfo:add')")
    @Log(title = "培训档案人员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StaffsafeInfo staffsafeInfo)
    {
        return toAjax(staffsafeInfoService.insertStaffsafeInfo(staffsafeInfo));
    }

    /**
     * 修改培训档案人员信息
     */
    @PreAuthorize("@ss.hasPermi('system:staffSafeinfo:edit')")
    @Log(title = "培训档案人员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StaffsafeInfo staffsafeInfo)
    {
        return toAjax(staffsafeInfoService.updateStaffsafeInfo(staffsafeInfo));
    }

    /**
     * 删除培训档案人员信息
     */
    @PreAuthorize("@ss.hasPermi('system:staffSafeinfo:remove')")
    @Log(title = "培训档案人员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(staffsafeInfoService.deleteStaffsafeInfoByIds(ids));
    }
}
